package com.javainterface.utils;

import java.net.URLDecoder;

public class CoreMailUtil {
    /**
     * 从接口返回结果中获取指定部分的值
     * @param encodedResult 接口返回结果
     * @param key 要获取值的key
     * @return 值
     * @throws Exception
     */
    public String getParameter(String encodedResult, String key) throws Exception {
        int start;
        if (encodedResult.startsWith(key + '=')) {
            start = key.length() + 1;
        } else {
            int i = encodedResult.indexOf('&' + key + '=');
            if (i == -1) {
                return null;
            }
            start = i + key.length() + 2;
        }
        int end = encodedResult.indexOf('&', start);
        String value = (end == -1)
                ? encodedResult.substring(start)
                : encodedResult.substring(start, end);
        return URLDecoder.decode(value, "GBK");
    }
}
